﻿
Imports xhtmlctrl

Public Class colorfulControl

    Public Shared ReadOnly defaultOriginColor As color = color.windowframe
    Public Shared ReadOnly defaultMouseonColor As color = New color("e0f2ee")

    Private Shared Function operateinvoke(ByVal inlineScript As inlineScript, ByVal color As color) As String
        assert(Not color Is Nothing, "color is nothing.")
        Return operate.invoke(inlineScript, "style.backgroundColor", "this", _
                              "'" + Convert.ToString(color) + "'", operOverride:="bgc")
    End Function

    Public Shared Sub invoke(ByVal inlineScript As inlineScript, ByVal control As xhtmlControl, _
                             Optional ByVal originalColor As color = Nothing, _
                             Optional ByVal mouseonColor As color = Nothing)
        assert(Not control Is Nothing, "control is nothing.")

        If originalColor Is Nothing Then
            originalColor = defaultOriginColor
        End If
        If mouseonColor Is Nothing Then
            mouseonColor = defaultMouseonColor
        End If

        control.onmouseover = operateinvoke(inlineScript, mouseonColor)
        control.onmouseout = operateinvoke(inlineScript, originalColor)
        control.style += "background:" + Convert.ToString(originalColor) + ";"
    End Sub

    Public Shared Sub invoke(ByVal page As xhtmlpage, ByVal control As xhtmlControl, _
                             Optional ByVal originalColor As color = Nothing, _
                             Optional ByVal mouseonColor As color = Nothing)
        'assert(Not page Is Nothing, "page is nothing.")
        If page Is Nothing Then
            invoke(CType(Nothing, inlineScript), control, originalColor, mouseonColor)
        Else
            invoke(page.inlineScript(), control, originalColor, mouseonColor)
        End If
    End Sub

End Class
